<?php

namespace App\Models\Factory;

use App\Models\AbsModelFactory;
use Illuminate\Support\Facades\Log;

/**
 * 短信操作工厂
 * Class SmsFactory
 * @package App\Models\Factory
 */
class SmsFactory extends AbsModelFactory
{

    /**
     * 请求创蓝发送短信
     */
    //创蓝发送短信接口URL, 如无必要，该参数可不用修改
    const API_SEND_URL='http://sms.253.com/msg/send';

    //创蓝短信余额查询接口URL, 如无必要，该参数可不用修改
    const API_BALANCE_QUERY_URL='http://sms.253.com/msg/balance';

    const API_ACCOUNT='N13811875123';//创蓝账号 替换成你自己的账号

    const API_PASSWORD='612941';//创蓝密码 替换成你自己的密码


	public static function sendCode($platform_name,$mobile) 
	{
                $msg    = "操作人员你好,合作平台--$platform_name"."需要审核";
                $needstatus = 1;
                //创蓝接口参数
                $postArr = array (
                    'un' => self::API_ACCOUNT,
                    'pw' => self::API_PASSWORD,
                    'msg' => $msg,
                    'phone' => $mobile,
                    'rd' => $needstatus,
                );
                $re = self::curlPost( self::API_SEND_URL , $postArr);
                if ($re)
                {
                    Log::info('审核短信已发送至操作人员手机:'.$mobile);

                }
                else
                {
                    Log::info('审核短信发送失败:'.$mobile);
                }


    }

    /**
     * 发送请求
     * @param $url
     * @param $postFields
     * @return mixed
     */
	private static function curlPost($url,$postFields)
	{
        $postFields = http_build_query($postFields);
        $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_URL, $url );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields );
        $result = curl_exec ( $ch );
        curl_close ( $ch );
        return $result;
    }


}
